CC=gcc
LD=ld
OBJDUMP=objdump
# AS = as
CFLAGS = -Wall -Werror -O1 -fno-omit-frame-pointer -ggdb -MD -ffreestanding -fno-common -nostdlib
LDFLAGS = -z max-page-size=4096
U=ulib
ULIB=$U/usys.o $U/printf.o $U/start.o

USER_PROG = _hello \
	_plus

.PHONY: all clean create_path
all: clean $(USER_PROG)

$U/usys.o: $U/usys.S
	$(CC) $(CFLAGS) -c -o $@ $^
$U/start.o: $U/start.S
	$(CC) $(CFLAGS) -c -o $@ $^

$U/usys.S: $U/usys.pl
	perl $U/usys.pl > $@

_%: %.o $(ULIB)
	$(LD) $(LDFLAGS) -o $@ $^
	$(OBJDUMP) -S $@ > $*.asm

%.o:%.c
	$(CC) $(CFLAGS) -c -o $@ $^

clean:
	rm -rf ulib/usys.S $(ULIB) $(USER_PROG) *.asm $(ULIB)/*.d
